<%@ page import="com.bdqn.zhang.pojo.Vivoproduct" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <!--360浏览器优先以webkit内核解析-->

    <title>H+ 后台主题UI框架 - 主页示例</title>

    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="static/js/plugins/layui/css/layui.css">
    <link href="static/css/font-awesome.css?v=4.4.0" rel="stylesheet"/>
    <link href="static/css/bootstrap.min.css?v=3.3.7" rel="stylesheet"/>
    <link href="static/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="static/css/animate.css" rel="stylesheet"/>
    <link href="static/css/style.css?v=4.1.0" rel="stylesheet"/>
    <style>
        #demo1 {
            width: 100px;
            height: 100px;
        }

        .ibox-title {
            min-height: 15px;
        }

        .ml_20 {
            margin-left: 20px;
        }

        .w100 {
            width: 100px !important;
        }

        .mt-60 {
            margin-top: -60px;
        }

        .layui-table-cell {

            text-align: center;

            height: auto;

            white-space: normal;

        }

        .layui-table img {
            max-width: 300px
        }

        .tishi {
            color: red;
        }
    </style>
</head>

<body class="gray-bg">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="demoTable">
                    搜索：
                    <div class="layui-inline">
                        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
                    </div>
                    <select style="height: 38px; border: darkgrey" class="ipt" id="role" name="city" lay-verify="">
                        <option value="全查询">全查询</option>
                        <option value="仅查询用户名">仅查询商品名称</option>
                        <option value="仅查询手机号">仅查询商品介绍</option>
                        <option value="仅查询性别">仅查询商品价格</option>
                        <option value="仅查询邮箱">仅查询商品上架时间</option>
                        <option value="通过状态查询">通过状态查询</option>
                    </select>
                    <button class="layui-btn" data-type="reload" id="ss">查询</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight mt-60">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="static/js/jquery-3.6.1.js"></script>
<script src="static/js/bootstrap.min.js?v=3.3.7"></script>
<script src="static/js/plugins/layer/layer.min.js"></script>
<script src="static/js/plugins/layui/layui.js"></script>

<!-- 自定义js -->
<script src="static/js/content.js"></script>


<!-- Peity -->
<script src="static/js/demo/bootstrap-table-demo.js"></script>

<!-- 欢迎信息 -->
<script src="static/js/welcome.js"></script>

<%--	<script type="text/html" id="checkboxTpl">--%>
<%--		<!-- 这里的 checked 的状态只是演示 -->--%>
<%--	<input type="checkbox" name="lock" value="{{d.id}}" title="锁定" lay-filter="lockDemo" {{ d.id==10006 ? 'checked' : ''--%>
<%--		}}>--%>
<%--	</script>--%>
<%--	<script type="text/html" id="barTb">--%>
<%--		<a class="layui-btn layui-btn-warm" lay-event="add">添加</a>--%>
<%--		<a class="layui-btn layui-btn-danger" lay-event="delete">批量删除</a>--%>
<%--	</script>--%>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="delAll"> 批量恢复</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="dells"> 批量删除</button>
    </div>
</script>
>
<%--	<script type="text/html" id="checkboxTpl">--%>
<%--		<!-- 这里的 checked 的状态只是演示 -->--%>
<%--		<input type="checkbox" name="lock" value="{{d.id}}" title="锁定" lay-filter="lockDemo" {{ d.id == 10006 ? 'checked' : '' }}>--%>
<%--	</script>--%>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">恢复到仓库</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script id="showScreenhost" type="text/html">
    {{# var srr=d.imglbt.split(",");
    for(var j in srr) { srr[j] }}
    <div class="imglbt"
         style="margin:0 10px; display:inline-block !important; display:inline;  max-width:70px; max-height:50px;">
        <img style=" max-width:70px; max-height:50px;" src="{{srr[j]}}"/>
    </div>
    {{# } }}
</script>
<script id="showScreenhosts" type="text/html">
    {{# var srr=d.imgzst.split(",");
    for(var j in srr) { srr[j] }}
    <div style="margin:0 10px; display:inline-block !important; display:inline;  max-width:70px; max-height:50px;">
        <img style=" max-width:70px; max-height:50px;" src="{{srr[j]}}"/>
    </div>
    {{# } }}
</script>
<script>
    window.name = "hsz";
    layui.use(['form', 'upload', 'table', 'element', 'layer', 'laydate'], function () {
        let $ = layui.jquery
        let upload = layui.upload
        let element = layui.element
        let layer = layui.layer;
        let laydate = layui.laydate;
        let table = layui.table;
        var form = layui.form
        laydate.render({
            elem: '#grounding_date'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            , range: ['#grounding_date_from', '#grounding_date_to']
        });
//初始化时查询
        let tableIns = table.render({
            elem: '#test',
            height: 480,
            url: 'spcx?opr=hsz',
            page: true,
            skin: 'line',
            toolbar: '#toolbarDemo',
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', title: '编号', sort: true,hide: true},
                {field: 'eid', title: 'eid', sort: true, hide: true},
                {field: 'yid', title: 'yid', sort: true, hide: true},
                {field: 'etype', title: '商品名称', align: 'center', sort: true},
                {field: 'descs', title: '介绍', align: 'center', sort: true},
                {field: 'img', title: '商品主图', align: 'center', templet: function (d) {
                        return '<img onclick="showimg(this)" id="driimg" style="display: inline-block; width: 50px; height: 50px;" src="' + d.img + '">';
                    }
                },
                {field: 'imglbt', title: '轮播图', align: 'center', templet: '#showScreenhost', hide: true},
                {field: 'imgzst', title: '轮播图展示', align: 'center', templet: '#showScreenhosts', hide: true},
                {field: 'image', title: '价格', align: 'center', sort: true},
                {field: 'pv', title: '点击量', align: 'center', sort: true},
                {field: 'kc', title: '库存', align: 'center', sort: true},
                {
                    field: 'status', title: '状态', align: 'center', sort: true, templet: function (d) {
                        var e = d.status;
                        if (e == 0) {
                            e = '<a style="color: #ed2a4a" lay-event="jin">下架状态 </a>';
                            return e;
                        } else if (e == 1) {
                            e = '<a style="color: #00FF00" lay-event="jin">上架状态</a>';
                            return e;
                        } else if (-1 == e) {
                            e = '<a style="color: #eea236" lay-event="jin">预售状态</a>';
                            return e;
                        }
                    }
                },
                {field: 'add_time', align: 'center', title: '时间', sort: true},
                {title: '操作', align: 'center', width: "17%", toolbar: '#barDemo'}]]
        })
        table.on('toolbar(test)', function (obj) {
            switch (obj.event) {  // 监听添加操作
                case 'delAll':
                    var checkStatus = table.checkStatus('test'),
                        data = checkStatus.data,
                        userId = "";
                    if (data.length > 0) {
                        for (var i in data) {
                            userId += data[i].yid + ",";
                        }
                        console.log(userId);//打印获取到选中的id，用，分割
                        layer.confirm('确定恢复选中的商品到仓库？', {icon: 3, title: '提示信息'}, function (index) {
                            $.ajax({
                                url: "spcx?opr=huifu",
                                type: "POST",
                                data: {id: userId},
                                success: function (msg) {
                                    if (msg == "true") {
                                        layer.msg('恢复成功!', {icon: 1, time: 1000});
                                        tableIns.reload({
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品批量恢复";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        top.window['butt'].frames.location.reload();
                                        top.window['upload'].frames.location.reload();
                                    } else {
                                        layer.msg('恢复失败', {time: 1000});
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品批量恢复";
                                        let jg="失败";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                    }
                                }
                            });
                        });
                    } else {
                        layer.msg('请选择恢复的数据!', {icon: 1, time: 1000});  //如果未选择数据，则提示。
                    }
                    break;
                case 'dells':
                    var checkStatus = table.checkStatus('test'),
                        data = checkStatus.data,
                        userId = "";
                    if (data.length > 0) {
                        for (var i in data) {
                            userId += data[i].yid + ",";
                        }
                        console.log(userId);//打印获取到选中的id，用，分割
                        layer.confirm('确定删除选中的商品？', {icon: 3, title: '提示信息'}, function (index) {
                            $.ajax({
                                url: "spcx?opr=delsc",
                                type: "POST",
                                data: {id: userId},
                                success: function (msg) {
                                    if (msg == "true") {
                                        layer.msg('删除成功!', {icon: 1, time: 1000});
                                        tableIns.reload({
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品批量删除";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        top.window['butt'].frames.location.reload();
                                        top.window['lode'].frames.location.reload();
                                    } else {
                                        layer.msg('删除失败', {time: 1000});
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品批量删除";
                                        let jg="失败";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                    }
                                }
                            });
                        });
                    } else {
                        layer.msg('请选择删除的数据!', {icon: 1, time: 1000});  //如果未选择数据，则提示。
                    }
                    break;
            }
        });
        //条件查询
        $("#ss").click(function () {
            var p_name = $(".layui-input").val()
            var myselect = document.getElementById("role");
            var index = myselect.selectedIndex;// selectedIndex是所选中的项的index
            myselect.options[index].value;
            let rr = myselect.options[index].text;
            if (p_name == null || p_name == "") {
                tableIns.reload({
                    url: 'spcx?opr=hsz',
                    page: {
                        curr: 1
                    }
                });
            } else if(rr == '通过状态查询' && p_name !== null || p_name !== ""){
                if (p_name == "下架状态" || p_name == "上架状态" || p_name == "预售状态") {
                    tableIns.reload({
                        url: 'spcx?opr=retrieve',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '全查询' && p_name !== null && p_name !== "") {
                    tableIns.reload({
                        url: 'spcx?opr=retrieve2',
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                }else if (rr == '仅查询商品名称' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'spcx?opr=retrievebg&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询商品介绍' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'spcx?opr=retrievebg&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询商品价格' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'spcx?opr=retrievebg&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                } else if (rr == '仅查询商品上架时间' && p_name !== null || p_name !== "") {
                    tableIns.reload({
                        url: 'spcx?opr=retrievebg&rr=' + rr,
                        where: {
                            p_name: p_name,
                        },
                        page: {
                            curr: 1
                        }
                    })
                }
            }
        })

        table.on('tool(test)', function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case'del':
                    layer.confirm('真的删除吗', function (index) {
                        $.ajax({
                            "url": "spcx?opr=delsc",
                            "dataType": 'text',
                            "type": 'post',
                            "data": {id: obj.data.yid},
                            async: false,
                            "success": function (date) {
                                if (date == "true") {
                                    layer.msg('删除成功', {icon: 1, time: 1500}, function () {
                                        tableIns.reload({
                                            where: {},
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品删除";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        top.window['butt'].frames.location.reload();
                                        top.window['lode'].frames.location.reload();
                                    });
                                } else {
                                    layer.msg('删除失败', {icon: 2, time: 1500});
                                    let b=sessionStorage.obs;
                                    let a=b.replace(/\"/g, "");
                                    let cz="商品回收站操作";
                                    let gn="商品删除";
                                    let jg="失败";
                                    $.ajax({
                                        "url": "gly?opr=xmr",
                                        "data": {name:a,cz:cz,gn:gn,jg:jg}
                                    })
                                }
                            }
                        });
                        // layer.close(index);
                    });
                    break;
                case 'edit':
                    layer.confirm('要恢复商品到仓库吗', function (index) {
                        $.ajax({
                            "url": "spcx?opr=huifu",
                            "dataType": 'text',
                            "type": 'post',
                            "data": {id: obj.data.yid},
                            async: false,
                            "success": function (date) {
                                if (date == "true") {
                                    layer.msg('恢复成功', {icon: 1, time: 1500}, function () {
                                        tableIns.reload({
                                            where: {},
                                            page: {
                                                curr: 1
                                            }
                                        });
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品恢复";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        top.window['butt'].frames.location.reload();
                                        top.window['upload'].frames.location.reload();
                                    });
                                } else {
                                    layer.msg('删除失败', {icon: 2, time: 1500});
                                    let b=sessionStorage.obs;
                                    let a=b.replace(/\"/g, "");
                                    let cz="商品回收站操作";
                                    let gn="商品恢复";
                                    let jg="失败";
                                    $.ajax({
                                        "url": "gly?opr=xmr",
                                        "data": {name:a,cz:cz,gn:gn,jg:jg}
                                    })
                                }
                            }
                        });
                        // layer.close(index);
                    });
                    break;
                case 'jin':
                    layer.confirm('确定要做此操作吗', function (index) {
                        $.ajax({
                            "url": "spcx?opr=ztxg",
                            "dataType": 'text',
                            "type": 'post',
                            "data": {id: obj.data.id, zhi: obj.data.status},
                            async: false,
                            "success": function (date) {
                                if (date == "true") {
                                    layer.msg('修改成功', {icon: 1, time: 1500}, function () {
                                        let b=sessionStorage.obs;
                                        let a=b.replace(/\"/g, "");
                                        let cz="商品回收站操作";
                                        let gn="商品状态修改";
                                        let jg="成功";
                                        $.ajax({
                                            "url": "gly?opr=xmr",
                                            "data": {name:a,cz:cz,gn:gn,jg:jg}
                                        })
                                        tableIns.reload({
                                            where: {},
                                            page: {
                                                curr: 1
                                            }
                                        });
                                    });
                                } else {
                                    layer.msg('修改失败', {icon: 2, time: 1500});
                                    let b=sessionStorage.obs;
                                    let a=b.replace(/\"/g, "");
                                    let cz="商品回收站操作";
                                    let gn="商品状态修改";
                                    let jg="失败";
                                    $.ajax({
                                        "url": "gly?opr=xmr",
                                        "data": {name:a,cz:cz,gn:gn,jg:jg}
                                    })
                                }
                            }
                        });
                        layer.close(index);
                    });
                    break;
            }
        });
    })

    function showimg(t) {
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: '516px',
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: '<img style="display: inline-block; width: 100%; height: 100%;" src="' + t.src + '">'
        });
    }
</script>
</body>

</html>